package com.iseastar.guojiang.task;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.iseastar.guojiang.dialog.DialogMgr;
import com.iseastar.guojiang.model.NewParcelBean;
import com.shouhuobao.station.R;
import com.shouhuobao.take.utils.StringUtils;

import java.util.ArrayList;

import droid.frame.activity.base.BaseAdapterWithImage;

/**
 * Created by joker on 2018/1/23.
 * 同城任务详情中包裹列表
 */
public class CourierTaskSameCityDetailAdapter extends BaseAdapterWithImage<NewParcelBean> {

    public CourierTaskSameCityDetailAdapter(ArrayList<NewParcelBean> items, Activity context, ViewGroup listView) {
        super(items, context, listView);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null || convertView.getTag() == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_courier_task_samecity_detail_parcel, parent, false);
            viewHolder.parcelNoTV = (TextView) convertView.findViewById(R.id.parcel_no_tv);
            viewHolder.parcelImageIV = (ImageView) convertView.findViewById(R.id.parcel_image_iv);
            viewHolder.orderNoTV = (TextView) convertView.findViewById(R.id.order_no_tv);
            viewHolder.bagCodeTV = (TextView) convertView.findViewById(R.id.bagcode_tv);
            viewHolder.sendCodeTV = (TextView) convertView.findViewById(R.id.send_code_tv);
            viewHolder.categoryInfoTV = (TextView) convertView.findViewById(R.id.category_info_tv);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        final NewParcelBean item = getItem(position);
        viewHolder.parcelNoTV.setText("1个包裹");//item.getTaskNo()
        showImage(item.getParcelImgUrl(), viewHolder.parcelImageIV, null);
        viewHolder.parcelImageIV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogMgr.showLargeStationPhoto(context, item.getParcelImgUrl());
            }
        });
        viewHolder.orderNoTV.setText("订单编号：" + item.getOrderId());
        if (StringUtils.isEmpty(item.getBagCode())) {
            viewHolder.bagCodeTV.setText("投递编号：无");
        } else {
            viewHolder.bagCodeTV.setText("投递编号：" + item.getBagCode());
        }
        if (StringUtils.isEmpty(item.getCheckCode())) {
            viewHolder.sendCodeTV.setText("寄件码：无");
        } else {
            viewHolder.sendCodeTV.setText("寄件码：" + item.getCheckCode());
        }
        viewHolder.categoryInfoTV.setText("物品：" + item.getCategory() + "/" + item.getWeight() + "kg");
        return convertView;
    }

    private class ViewHolder {
        TextView parcelNoTV;//包裹序号
        ImageView parcelImageIV;//包裹图片
        TextView orderNoTV;//订单编号
        TextView bagCodeTV;//投递编号
        TextView sendCodeTV;//寄件码
        TextView categoryInfoTV;//物品信息
    }
}
